using System.Windows;
using Coniometer.Pages;
using Coniometer.Pages.SettingPages;
using Coniometer.Pages.SettingPages.UserPages;
using Coniometer.Service;
using Coniometer.ViewModels;
using Coniometer.Views;
using Prism.DryIoc;
using Prism.Ioc;
using Prism.Regions;

namespace Coniometer
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : PrismApplication
    {
        protected override Window CreateShell()
        {
            var mainWindow = Container.Resolve<MainWindow>();
            mainWindow.Loaded += delegate
            {
                var regionManager = Container.Resolve<IRegionManager>();
                regionManager.RequestNavigate("ContentRegion", "SimplePage");
            };
            return mainWindow;
        }

        protected override void InitializeShell(Window shell)
        {
            //实现登录
            var loginWindow = Container.Resolve<LoginWindow>();
            var result = loginWindow.ShowDialog();
            if (result == null)
            {
                Current.Shutdown();
                return;
            }

            if (result.Value)
            {
                base.OnInitialized();
            }
            else
            {
                Current.Shutdown();
            }
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            //Views
            containerRegistry.Register<MainWindow>();

            //ViewModels
            containerRegistry.Register<MainWindowViewModel>();

            //Data
            containerRegistry.Register<IAppDataService, AppDataServiceImpl>();

            //Navigation
            containerRegistry.RegisterForNavigation<SimplePage, SimplePageViewModel>();
            containerRegistry.RegisterForNavigation<DataPage, DataPageViewModel>();
            containerRegistry.RegisterForNavigation<TaskPage, TaskPageViewModel>();
            containerRegistry.RegisterForNavigation<SettingPage, SettingPageViewModel>();

            //DataPage二级页面Navigation
            containerRegistry.RegisterForNavigation<SimpleDataPage, SimpleDataPageViewModel>();
            containerRegistry.RegisterForNavigation<SopDataPage, SopDataPageViewModel>();
            containerRegistry.RegisterForNavigation<AuditTrailPage, AuditTrailPageViewModel>();
            
            //SettingPage二级页面Navigation
            containerRegistry.RegisterForNavigation<SpaceSchemePage, SpaceSchemePageViewModel>();
            containerRegistry.RegisterForNavigation<SimpleSchemePage, SimpleSchemePageViewModel>();
            containerRegistry.RegisterForNavigation<PrintSchemePage, PrintSchemePageViewModel>();
            containerRegistry.RegisterForNavigation<TimeSettingPage, TimeSettingPageViewModel>();
            containerRegistry.RegisterForNavigation<DeviceInfoPage, DeviceInfoPageViewModel>();
            containerRegistry.RegisterForNavigation<NetworkConfigPage, NetworkConfigPageViewModel>();
            containerRegistry.RegisterForNavigation<UserManagementPage, UserManagementPageViewModel>();
            containerRegistry.RegisterForNavigation<HelpCenterPage, HelpCenterPageViewModel>();
            containerRegistry.RegisterForNavigation<CalibrationPage, CalibrationPageViewModel>();
            
            //UserManagementPage三级页面Navigation
            containerRegistry.RegisterForNavigation<ManagementPage, ManagementPageViewModel>();
            containerRegistry.RegisterForNavigation<PermissionPage, PermissionPageViewModel>();
            
            //Dialog
        }
    }
}